package com.hopes.bizz.risk.hid.dto;

import cn.hutool.core.date.DateUtil;
import com.hopes.bizz.common.core.util.StringUtils;
import com.hopes.bizz.risk.common.constant.HidDicConstant;
import com.hopes.bizz.risk.hid.entity.RiskHidSuperviseEntity;
import com.hopes.boss.common.security.util.SecurityUtils;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.time.LocalDateTime;
import java.util.List;

/**
 * @author lyb
 * @version 1.0
 * @date 2024/2/22 16:14
 */

@Data
public class RiskHidSuperviseDTO {

    /**
     * 隐患标识
     */
    @NotNull(message = "隐患标识不能为空")
    private Long hidId;

    /**
     * 隐患名称
     */
    @NotBlank(message = "隐患名称不能为空")
    private String hidName;

    /**
     * 督办方式
     */
    @NotNull(message = "督办方式不能为空")
    @Size(min = 1, message = "督办方式不能为空")
    private List<Integer> superviseWay;

    /**
     * 督办通知内容
     */
    @NotBlank(message = "督办通知内容不能为空")
    private String superviseContent;

    /**
     * 督办通知接收人
     */
    @NotBlank(message = "督办通知接收人不能为空")
    private String receiver;

    /**
     * 要求完成时间
     */
    @NotNull(message = "要求完成时间不能为空")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime requireCompleteTime;

    /**
     * 要求回复时间
     */
    @NotNull(message = "要求回复时间不能为空")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime requireRecoverTime;


    public RiskHidSuperviseEntity toEntity() {
        RiskHidSuperviseEntity riskHidSupervise = new RiskHidSuperviseEntity();
        riskHidSupervise.setHidId(hidId);
        riskHidSupervise.setHidName(hidName);
        riskHidSupervise.setReceiver(receiver);
        riskHidSupervise.setRequireCompleteTime(requireCompleteTime);
        riskHidSupervise.setRequireRecoverTime(requireRecoverTime);
        riskHidSupervise.setSuperviseContent(superviseContent);
        riskHidSupervise.setSuperviseTime(LocalDateTime.now());
        riskHidSupervise.setSuperviseWay(StringUtils.join(",", superviseWay));
        return riskHidSupervise;
    }

    public Boolean appWay() {
        return superviseWay.contains(HidDicConstant.RISK_HID_SUPERVISE_WAY_APP);
    }

    public Boolean webWay() {
        return superviseWay.contains(HidDicConstant.RISK_HID_SUPERVISE_WAY_WEB);
    }

    public String buildTitle() {
        StringBuilder sb = new StringBuilder(HidDicConstant.RISK_HID_SUPERVISE_TITLE);
        sb.append(" | ").append("(").append(hidName).append(")")
                .append("隐患未完成整改验收");
        return sb.toString();
    }

    public String buildContent() {
        StringBuilder sb = new StringBuilder(HidDicConstant.RISK_HID_SUPERVISE_TITLE);
        sb.append(System.lineSeparator());
        sb.append("要求回复时间: ").append(DateUtil.formatLocalDateTime(requireRecoverTime));
        sb.append(System.lineSeparator());
        sb.append("要求完成时间: ").append(DateUtil.formatLocalDateTime(requireCompleteTime));
        sb.append(System.lineSeparator());
        sb.append("督办通知下法人: ").append(SecurityUtils.getUser().getName());
        return sb.toString();
    }
}
